package lanou.autohome.collection;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import lanou.autohome.R;
import lanou.autohome.basetool.NetTool;

/**
 * Created by dllo on 16/9/2.
 */
public class CollectionAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<CollectionLocalBean> collectionLocalBeen;

    public CollectionAdapter(Context mContext) {
        this.mContext = mContext;
    }


    public void setCollectionLocalBeen(ArrayList<CollectionLocalBean> collectionLocalBeen) {
        this.collectionLocalBeen = collectionLocalBeen;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return collectionLocalBeen != null ? collectionLocalBeen.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHoldero viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_collection, null);
            viewHolder = new ViewHoldero(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHoldero) convertView.getTag();
        }
        CollectionLocalBean bean = collectionLocalBeen.get(position);
        viewHolder.name.setText(bean.getName());
        viewHolder.levelname.setText(bean.getLevelname());
        viewHolder.fctprice.setText(bean.getFctprice());
        NetTool mNetTool = new NetTool();
        mNetTool.getImage(bean.getLogo(),viewHolder.logo);
//        MyBemoUser myBemoUser = BmobUser.getCurrentUser(MyBemoUser.class);
//        if (myBemoUser != null) {
//            viewHolder.name.setText(myBemoUser.getUsername());
//            viewHolder.levelname.setText();
//        }
        return convertView;
    }

    public class ViewHoldero {
        TextView name;
        TextView fctprice;
        TextView levelname;
        ImageView logo;

        public ViewHoldero(View convertView) {
            name = (TextView) convertView.findViewById(R.id.name_collection_item);
            fctprice = (TextView) convertView.findViewById(R.id.fctprice_collection_item);
            levelname = (TextView) convertView.findViewById(R.id.levename_collection_item);
            logo = (ImageView) convertView.findViewById(R.id.logo_collection_item);
        }
    }
}
